//
// Created by dddgzc on 2025/1/24.
//

#include "../include/Vector2.h"

Vector2::Vector2(const float x, const float y): x(x), y(y) {

}

Vector2 Vector2::operator+(const Vector2 &vec) const {
    return Vector2(vec.x + x, vec.y + y);
}

void Vector2::operator+=(const Vector2 &vec) {
    this->x += vec.x;
    this->y += vec.y;
}

void Vector2::operator-=(const Vector2 &vec) {
    this->x -= vec.x;
    this->y -= vec.y;
}

Vector2 Vector2::operator-(const Vector2 &vec) const {
    return Vector2(x - vec.x, y - vec.y);
}

float Vector2::operator*(const Vector2 &vec) const {
    return x * vec.x + y * vec.y;
}

Vector2 Vector2::operator*(float val) const {
    return Vector2(val * x, val * y);
}

void Vector2::operator*=(float val) {
    this->x *= val;
    this->y *= val;
}

float Vector2::length() const {
    return sqrt(x * x + y * y);
}

Vector2 Vector2::normalized() const {
    float len = length();
    if (len == 0) return Vector2(0, 0);
    return Vector2(x / len, y / len);
}



